package org.dev.vlp.controller;

import com.google.gson.JsonObject;
import org.dev.vlp.bean.JsonResponse;
import org.dev.vlp.constants.Roles;
import org.dev.vlp.dto.LearnParam;
import org.dev.vlp.entity.Word;
import org.dev.vlp.interceptor.RequiredPermission;
import org.dev.vlp.service.LearnRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Description
 * Param
 * return
 * Author:86184
 * Date: 2023/1/23
 */
@RestController
@RequestMapping("/learn")
@RequiredPermission({Roles.ROLE_USER})
public class LearnController extends BaseController{

    @Autowired
    private LearnRecordService learnRecordService;

    @GetMapping
    public JsonResponse<Object> plan() {
        return JsonResponse.success(learnRecordService.getNeedLearnAndReview((int)getUid()));
    }

    /**
     * 获取一批未学习单词接口
     * @return
     */
    @GetMapping("/newWords")
    public JsonResponse<Object> getNewWords(@RequestParam Integer needCount){
        List<Word> newWords = learnRecordService.getNewWords((int)getUid(),needCount);
        return JsonResponse.success(newWords);
    }

    @GetMapping("/reviewWords")
    public JsonResponse<Object> getReviewWords(){
        List<Word> reviewWords = learnRecordService.getNeedReviewWords((int)getUid());
        return JsonResponse.success(reviewWords);
    }

    /**
     * 学习新单词，添加记忆记录接口
     * @return
     */
    @PostMapping("/newWord")
    public JsonResponse<Object> learnNewWord(@RequestBody LearnParam learnParam){
        List<Integer> wordIds = learnParam.getWordIds();
        learnRecordService.learnNewWord((int)getUid(),wordIds);
        return JsonResponse.success();

    }

    /**
     * 复习单词，更细记忆记录接口
     * @return
     */
    @PutMapping("/reviewWord")
    public JsonResponse<Object> updateReviewWord(@RequestBody LearnParam learnParam){
        List<Integer> wordIds = learnParam.getWordIds();
        List<Integer> reviews = learnParam.getReviews();
        learnRecordService.reviewOldWord(wordIds,reviews,(int)getUid());
        return JsonResponse.success();
    }
}
